{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://api.m.taobao.com/h5/mtop.taobao.couponmtopreadservice.findshopbonusactivitys/2.0/?appKey=12574478&t=1493863879898&sign=495c9286d932694d422027ac67ac8a3b&api=mtop.taobao.couponMtopReadService.findShopBonusActivitys&v=2.0&AntiFlood=true&ecode=1&type=jsonp&dataType=jsonp&callback=mtopjsonp2&data={\"uuid\":\"0ad0e948a95848589bb386c039255e17\",\"sellerId\":\"3091520751\",\"queryShop\":true}'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import hashlib\n",
    "import time\n",
    "import random\n",
    "\n",
    "def get_json_url(m_h5_tk, activity_id, seller_id):\n",
    "    '''\n",
    "    Function doc\n",
    "    获取优惠券json的url\n",
    "    '''\n",
    "    isgn = m_h5_tk.replace('_','&') + '&12574478&'\n",
    "    m = hashlib.md5()\n",
    "    m.update(isgn)\n",
    "    isgn = m.hexdigest()\n",
    "    url = 'https://api.m.taobao.com/h5/mtop.taobao.couponmtopreadservice.findshopbonusactivitys/2.0/?appKey=12574478&t=%s&sign=%s&api=mtop.taobao.couponMtopReadService.findShopBonusActivitys&v=2.0&AntiFlood=true&ecode=1&type=jsonp&dataType=jsonp&callback=mtopjsonp2&data=%s'\n",
    "    data = '{\"uuid\":\"%s\",\"sellerId\":\"%s\",\"queryShop\":true}'%(activity_id,seller_id)\n",
    "    t = str(int(time.time()))+str(random.choice(range(100,999)))\n",
    "    url = url%(t,isgn,data)\n",
    "    return url\n",
    "url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://api.m.taobao.com/h5/mtop.taobao.couponmtopreadservice.findshopbonusactivitys/2.0/?appKey=12574478&t=1493796006687&sign=d7d262556113bf4f84e177b1d86e7fd2&api=mtop.taobao.couponMtopReadService.findShopBonusActivitys&v=2.0&AntiFlood=true&ecode=1&type=jsonp&dataType=jsonp&callback=mtopjsonp2&data={\"uuid\":\"8d6cc7348b0445ea978c57d182db6b30\",\"sellerId\":\"628189716\",\"queryShop\":true}'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import urllib2\n",
    "\n",
    "url = 'https://api.m.taobao.com/h5/mtop.taobao.couponmtopreadservice.findshopbonusactivitys/2.0/?appKey=12574478&t=1493796006687&sign=d7d262556113bf4f84e177b1d86e7fd2&api=mtop.taobao.couponMtopReadService.findShopBonusActivitys&v=2.0&AntiFlood=true&ecode=1&type=jsonp&dataType=jsonp&callback=mtopjsonp2&data=%7B%22uuid%22%3A%228d6cc7348b0445ea978c57d182db6b30%22%2C%22sellerId%22%3A%22628189716%22%2C%22queryShop%22%3Atrue%7D'\n",
    "urllib2.unquote(url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1493863779537'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "import random\n",
    "time.time()\n",
    "str(int(time.time()))+str(random.choice(range(100,999)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'d7d262556113bf4f84e177b1d86e7fd2'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 = 'a012838341af0cd39ff64c654e862f8d&1493796006687&12574478&{\"uuid\":\"8d6cc7348b0445ea978c57d182db6b30\",\"sellerId\":\"628189716\",\"queryShop\":true}'\n",
    "m = hashlib.md5()\n",
    "m.update(str1)\n",
    "m.hexdigest()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
